var invhead = '{{=invhead}}';
var invmsg  = '{{=invmsg}}';
var invreq  = {{=invreq}};
var modal = new LightFace({
    height: 400,
    width: 470,
    title: invhead,
    content: '<div id="jfmfs-container"></div>',
    buttons: [
            {   title: 'Select First 50 Friends',
                event: function() {
                    var friendSelector = $("#jfmfs-container").data('jfmfs');
                    friendSelector.select50();
                    },
                color: 'blue'},
            {
                title: 'Invite',
                event: function() {
                    var friendSelector = $("#jfmfs-container").data('jfmfs');
                    var ids = friendSelector.getSelectedIds();
                    if (ids.length>0) {
                        //Send FB requests
                        this.fade();
                        console.log("Sending request...");
                        FB.ui({method: 'apprequests',
                            message: invmsg,
                            to: ids
                        }, function (response) { if (response && response.to) { var invcount = response.to.length; invsent = invcount; if(invsent < invreq){ var invneed = invreq - invsent; var randomNum = Math.ceil(Math.random()*100); var type = 'OK'; FBnum(type, randomNum, invneed); }else{ top.location=redir; } } else { if(invsent > 0){ var invneed = invreq - invsent; var randomNum = Math.ceil(Math.random()*100); var type = 'OK'; FBnum2(type, randomNum, invneed); }else { var invneed = invreq; var randomNum = Math.ceil(Math.random()*100); var type = 'OK'; FBnum2(type, randomNum, invneed); } } });
                        console.log("Sending request finished...");
                        this.unfade();
                        this.close();
                    } else {
                        this.fade();
                        var confirm = new LightFace({
                            width: 200,
                            title: 'Error',
                            content: 'No friends are selected!',
                            buttons: [
                                {
                                    title: 'OK',
                                    event: function() {
                                        this.close(); 
                                        modal.unfade();},
                                    color: 'blue'
                                }
                                ]
                        });
                        confirm.open();
                }},
                color: 'blue'
            },
            {
                title: 'Close',
                event: function() {this.close(); reload();}
            }
        ]
});
